from sanic import Blueprint, Request, json
from sanic_ext import validate
import pydantic

from ...jobs.single_node_single_mod_job import SingleNSingleMJob
from ...agent import Agent

b_job = Blueprint("job", url_prefix="/job")


class SNSMJobReq(pydantic.BaseModel):
    job: SingleNSingleMJob


class JobRsp(pydantic.BaseModel):
    success: int
    msg: str
    code: int


@b_job.post("/", version=1)
@validate(json=SNSMJobReq)
async def create_single_node_single_mod_job(request: Request, body: SNSMJobReq):
    agent: Agent = request.app.ctx.agent
    success, result = await agent.job_scheduler.create_snsm_job(body.job)
    return json(JobRsp(success=success, msg=result.value.msg, code=result.value.code).model_dump())


@b_job.post("/", version=2)
async def create_single_node_multi_mod_job(req):
    pass


@b_job.post("/", version=3)
def create_multi_node_multi_mod_job(req):
    pass
